import java.util.HashSet;
import java.util.Set;

public class Solution202 {
    public boolean isHappy(int n) {
        Set<Integer> set=new HashSet<>();
        while (n!=1){
            String t=String.valueOf(n);
            int k=0;
            for (char c : t.toCharArray()) {
                k=k+(c-'0')*(c-'0');
            }
            if (set.contains(k)){
                return false;
            }else {
                set.add(k);
            }
            n=k;
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(new Solution202().isHappy(19));
    }
}
